<?php
/*##################################################

# 模块功能：lywq自动触发任务配置
###################################################*/
error_reporting(0);
header("Content-Type: text/html;charset=utf-8");
if(!@$_SERVER['HTTP_REFERER']) header('location:/');

$ssl = 'http://';
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
    $ssl = 'https://';
}

$info = 'info.ini';
$infoL = '../../application/admin/view/lywq/Autotrigger/info.ini';
$Lywqautotrigger = 'expand/Lywqautotrigger.php';
$LywqautotriggerL = '../../application/api/controller/Lywqautotrigger.php';
$index_html = 'expand/index.html';
$index_htmlL = '../../application/admin/view/lywq/Autotrigger/html/index.html';
$info_html = 'expand/info.html';
$info_htmlL = '../../application/admin/view/lywq/Autotrigger/html/info.html';
$log_html = 'expand/log.html';
$log_htmlL = '../../application/admin/view/lywq/Autotrigger/html/log.html';
$version = parse_ini_file($info);
$versionL = parse_ini_file($infoL);

if (!file_exists($LywqautotriggerL) || !file_exists($index_htmlL) || !file_exists($info_htmlL) || !file_exists($log_htmlL) || $version['version']!=$versionL['version']) {
  // 删除php文件
  if(!unlink($LywqautotriggerL)){
    unlink('../../application/api/controller/Lywqautotrigger.php');
  }
	copy($info,$infoL);
	copy($Lywqautotrigger,$LywqautotriggerL);
  
	// 创建html文件夹
  mkdir('../../application/admin/view/lywq/Autotrigger/html', 0777,true);
	copy($index_html,$index_htmlL);
	copy($info_html,$info_htmlL);
	copy($log_html,$log_htmlL);
}

$admin_id = $_COOKIE["admin_id"];
$admin_name = $_COOKIE["admin_name"];
$admin_check = $_COOKIE["admin_check"];
$data = '?admin_id='.$admin_id.'&admin_name='.$admin_name.'&admin_check='.$admin_check;
$ischushihua = file_get_contents($ssl.$_SERVER['HTTP_HOST'] .'/api.php/Lywqautotrigger/ischushihua'.$data);
if ($ischushihua=='false') {
    $initialize = file_get_contents($ssl.$_SERVER['HTTP_HOST'] .'/api.php/Lywqautotrigger/initialize'.$data);
    if ($initialize==2) {
        exit('初始化失败，请联系插件开发者qq 1520431201');
    }
}

if (!file_exists($info)) {
	exit('未检测到info.ini配置文件,请检查 addons/Autotrigger/info.ini 文件是否存在！');
}
$config = './config/config.php';
if (!file_exists($config)) {
  $configfile = fopen("./config/config.php", "w") or die("Unable to open file!");
  fwrite($configfile, "<?php $"."lywq "."=array ();");
  fclose($configfile);
}
require($config);
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>lywq自动触发任务设置</title>
    <link href="/static/layui/css/layui.css" rel="stylesheet" type="text/css" />
    <script src="/static/layui/layui.js" type="text/javascript" charset="utf-8"></script>
	<script src="/static/js/jquery.js"></script>
	<style>.layui-input-inline textarea{min-width:300px;min-height:150px;}
	.layui-form-item .layui-form-label{min-width:130px;}
	</style>
</head>
<body style="margin:20px 20px">
<style>.showpic {position:absolute; max-width:400px; max-height:500px; text-align:center; line-height:150%; border:2px solid #DEEFFA; padding:5px; background:#FFFFFF;  z-index:99999;}</style>
<div class="showpic" style="display:none;"><img class="showpic_img" width="100%" height="100%"></div>
<form class="layui-form layui-form-pane" action="">
<div class="layui-tab">
  <ul class="layui-tab-title">
    <li class="layui-this">lywq自动触发任务</li>
    <li>赞助支持</li>
    <li>基础设置</li>
    <li>任务列表</li>
    <li>日志列表</li>
  </ul>
  <div class="layui-tab-content">
    <!-- 介绍页 -->
    <div class="layui-tab-item layui-show">
      <blockquote class="layui-elem-quote layui-quote-nm">
        <p>欢迎使用lywq自动触发任务插件</p>
        <p><span style="color:red;">注意：</span>本插件为模板辅助插件，请在模板中（<span style="color:red;">public / foot.html文件</span>）插入如下代码：<span style="font-weight:bold;color:green;">{php}require('./addons/Autotrigger/html/lywq_Autotrigger.html');{/php}</span></p>
      </blockquote>
      <table class="layui-table">
        <colgroup>
          <col width="100">
            <col width="150">
              <col></colgroup>
        <thead>
          <tr>
            <th colspan="2" scope="col">插件简介</th>
            <th colspan="1" scope="col">使用说明</th></tr>
        </thead>
        <tbody>
          <tr>
            <td>名称</td>
            <td>
              <a href="https://www.muyin.life" target="_blank"><?php echo $version['title'] ;?> <?php echo $version['version'] ;?></a></td>
            <td>1. PHP版本≥5.6</td></tr>
          <tr>
            <td>作者</td>
            <td>
              <a href="<?php echo $version['website'] ;?>" target="_blank"><?php echo $version['author'] ;?></a></td>
            <td>2. 插件均为作者原创开发，不定时更新。</td></tr>
          <tr>
            <td>官方Q群</td>
            <td>
              <a href="https://jq.qq.com/?_wv=1027&k=szDVe4dO" target="_blank">294075802</a></td>
            <td>3. 意见、反馈、功能建议，请加入官方QQ群一起沟通交流！</td></tr>
          <tr>
            <td>作者QQ</td>
            <td>
              <a href="http://wpa.qq.com/msgrd?v=3&uin=<?php echo $version['qq'] ;?>&site=qq&menu=yes" target="_blank"><?php echo $version['qq'] ;?></a></td>
            <td>4. 唯一官方QQ，购买非官方制作源码，无任何技术支持及售后服务！</td></tr>
          <tr>
            <td>更新时间</td>
            <td><?php echo $version['updatetime'] ;?></td>
            <td>5. 肆意散播转售或者倒卖，将视为放弃一切技术支持。</td></tr>
          <tr>
            <td style="color:red;">使用教程</td>
            <td>
              <a href="<?php echo $version['tutorial'] ;?>" style="color:blue;" target="_blank">查看教程</a></td>
            <td>6. 使用盗版源码遇到任何问题本人概不负责！</td></tr>
          <tr>
            <td style="color:red;">更新日志</td>
            <td colspan="2" style="color:#2E8B57;">
              <?php echo $version['updatelog'] ;?></td></tr>
          <tr>
            <td colspan="3">请务必尊重知识产权，严格保证不恶意传播产品源码、不得直接对源码进行二次转售或倒卖等。一经发现，我们有权利终止你在我方购买的所有源码的售后技术支持。</td></tr>
        </tbody>
      </table>
    </div>

    <!-- 赞助支持 -->
    <div class="layui-tab-item">
      <blockquote class="layui-elem-quote layui-quote-nm">
        <p>您好，首先非常感谢您使用lywq自动触发任务插件！</p>
        <p>本插件为<span style="color:red;">完全免费</span>插件，目前作者唯一收入为捐赠，免费程序的开发离不开金钱，还请各位多多支持！</p>
        <p></p>
        <p></p>
      </blockquote>
      <!--赞赏二维码-->
      <table class="layui-table">
        <thead>
          <tr>
            <th colspan="3">赞赏部分</th>
        </tr>
        </thead>
        <tbody>
            <tr align="center">
                <td width="20%">微信二维码</td>
                <td width="20%">支付宝二维码</td>
                <td width="60%">话说</td>
            </tr>
            <tr align="center">
                <td width="20%"><a href="https://s3.ax1x.com/2021/02/01/yVBih8.png" target="_blank"><img src="https://s3.ax1x.com/2021/02/01/yVBih8.png" width="auto" /></a></td>
                <td width="20%"><a href="https://s3.ax1x.com/2021/02/01/yVBk9S.jpg" target="_blank"><img src="https://s3.ax1x.com/2021/02/01/yVBk9S.jpg" width="280px" /></a></td>
                <td width="60%">
                <p style="color:#FF0000;">自愿赞赏，不强求，金额随意，一分也是爱！</p>
                <p style="color:#FF8C00;">您的支持将是我最大的动力，加油，奥力给！</p>
                <p><a style="color:	#1E90FF;" href="https://jq.qq.com/?_wv=1027&k=szDVe4dO" target="_blank">点击进群，一起交流插件！</a></p>
                </td>
            </tr>
        </tbody>
      </table>
      <!--广告赞助-->
      <table class="layui-table">
        <thead>
          <tr>
            <th colspan="3">广告部分</th>
        </tr>
        </thead>
        <tbody>
            <tr align="center">
                <td>
                   <iframe src="https://www.muyin.life/ads/lywq_Autotrigger/lywq_Autotrigger_ads.html" width="100%" height="320px" frameborder="0" scrolling="yes"></iframe>
                </td>
            </tr>
        </tbody>
      </table>
      <!--友情链接-->
      <table class="layui-table">
        <thead>
          <tr>
            <th colspan="3">友链部分</th>
        </tr>
        </thead>
        <tbody>
            <tr align="center">
                <td>
                   <iframe src="https://www.muyin.life/ads/lywq_Autotrigger/lywq_Autotrigger_link.html" width="100%" height="180px" frameborder="0" scrolling="yes"></iframe>
                </td>
            </tr>
        </tbody>
      </table>
    </div>

    <!--基础设置-->
    <div class="layui-tab-item">
      
	    <div class="layui-form-item">
           <label class="layui-form-label">请求token：</label>
           <div class="layui-input-inline">
              <input type="text" name="lywq_Autotrigger_token" placeholder="请填写token" value="<?php echo $lywq['Autotrigger']['token'];?>" autocomplete="off" class="layui-input">
           </div>
           <div class="layui-form-mid layui-word-aux">为了确保接口的安全性，请务必设置token</div>
	    </div>

        <div class="layui-form-item">
           <label class="layui-form-label">请求方式：</label>
           <div class="layui-input-inline" style="width:600px;">
             <input type="radio" name="lywq_Autotrigger_type" value="0" title="关闭" <?php echo $lywq['Autotrigger']['type']==0?'checked':'';?>>
             <input type="radio" name="lywq_Autotrigger_type" value="1" title="自动触发" <?php echo $lywq['Autotrigger']['type']==1?'checked':'';?>>
             <input type="radio" name="lywq_Autotrigger_type" value="2" title="宝塔定时" <?php echo $lywq['Autotrigger']['type']==2?'checked':'';?>>
           </div>
        </div>
        <div class="layui-form-item" <?php if ($lywq['Autotrigger']['type'] != 1) { echo 'style="display:none;"';} ?> >
            <blockquote class="layui-elem-quote layui-quote-nm">
            <p><span style="color:red;">小提示：</span>当有访客访问网站时，执行触发操作，结合合理的定时任务时间间隔，可以有效地实现定时触发任务。<span style="font-weight:bold;color:green;">当访客非常少的时候，可能会造成时间差，一般情况下不会出现，除非你的网站没人进。</span></p>
            </blockquote>
        </div>
        <div class="layui-form-item" <?php if ($lywq['Autotrigger']['type'] != 2) { echo 'style="display:none;"';} ?> >
            <blockquote class="layui-elem-quote layui-quote-nm">
            <p><span style="color:red;">小提示：</span>宝塔添加定时任务，访问url：<span style="font-weight:bold;color:green;"><?php echo $ssl.$_SERVER['HTTP_HOST'];?>/api.php/Lywqautotrigger/execute?token=<?php echo $lywq['Autotrigger']['token'];?></span></p>
            </blockquote>
        </div>


        <!-- 保存 -->
        <div class="layui-form-item">
          <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="systemsave">保存配置</button></div>
        </div>
    </div>

    <!-- 任务列表 -->
    <div class="layui-tab-item">
      <blockquote class="layui-elem-quote layui-quote-nm">
        <iframe src="<?php echo $ssl.$_SERVER['HTTP_HOST'];?>/api.php/Lywqautotrigger/index" width="100%" height="460px" frameborder="0" scrolling="yes"></iframe>
        </blockquote>
    </div>
    
    <!-- 日志列表 -->
    <div class="layui-tab-item">
      <blockquote class="layui-elem-quote layui-quote-nm">
        <iframe src="<?php echo $ssl.$_SERVER['HTTP_HOST'];?>/api.php/Lywqautotrigger/log" width="100%" height="460px" frameborder="0" scrolling="yes"></iframe>
        </blockquote>
    </div>
    
  </div>
</div>
</form>


<script>
layui.use(['layer', 'form', 'table', 'element'], function(){
  var layer = layui.layer 
  ,form = layui.form
  ,table = layui.table
  ,element = layui.element

  form.on('submit(systemsave)', function(data){
    console.log(JSON.stringify(data.field));
    data.field.lywq_Autotrigger_type = data.field.lywq_Autotrigger_type?data.field.lywq_Autotrigger_type:'1';
    $.ajax({
        url: "save.php",
        data: data.field,
        type: "post", 
		dataType: 'json',
        success: function (data) {
			layer.msg(data.msg, {icon: data.icon});
            form.render();
            location.reload();
        },
        error: function () {
            layer.alert("保存配置执行异常!", {icon: 5});
        }
    });				  
    return false;	
  });
});
</script>
</body>
</html>